package cn.tedu.goods.management.controller;


import cn.tedu.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.common.web.JsonResult;
import cn.tedu.goods.management.pojo.param.GoodsAddNewParam;
import cn.tedu.goods.management.pojo.param.GoodsAvatarParam;
import cn.tedu.goods.management.pojo.param.GoodsUpdateParam;
import cn.tedu.goods.management.service.IGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/packages/")
@Api(tags = "1. 套餐管理")
public class GoodsController {
    @Autowired
    private IGoodsService goodsService;

    @PostMapping("{goodNames}/avatar")
    public JsonResult avatar(@PathVariable String goodNames, GoodsAvatarParam goodsAvatarParam){

        System.out.println("currentPrincipal = " + goodNames + ", staffAvatarParam = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + goodsAvatarParam);
        goodsService.avatar(goodNames,goodsAvatarParam);
        return JsonResult.ok();
    }


    @ApiOperation("新增商品")
    @PostMapping("add-new")
    private JsonResult addNew(@Validated GoodsAddNewParam goodsAddNewParam){
        goodsService.addNew(goodsAddNewParam);
        String message = "添加套餐成功";
        return JsonResult.ok(message);
    }

    @ApiOperation("查询商品列表(管理员)")
    @GetMapping("admin")
    private JsonResult selectGoodsList(){
        return JsonResult.ok(goodsService.selectGoodsList());
    }

    @ApiOperation("查询商品列表(用户)")
    @GetMapping("user")
    private JsonResult selectGoodsListForUser(){
        return JsonResult.ok(goodsService.selectGoodsListForUser());
    }

    @ApiOperation("根据ID删除类别")
    @PostMapping("{id}/delete")
    public JsonResult deleteById(@PathVariable Long id) {
        goodsService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据ID修改商品")
    @PostMapping("{id}/update")
    private JsonResult updateById(@Validated GoodsUpdateParam goodsUpdateParam){
        goodsService.updateById(goodsUpdateParam);
        return JsonResult.ok();
    }
}
